<?php

namespace App\Http\Controllers\Home;

use App\Models\Collections;
use App\Models\Goods;
use App\Models\Order;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class CollectionController extends Controller
{
    public function collect(Goods $goods){
//        dd($goods->toArray());
        if($collection=Collections::where('user_id',auth()->id())->where('goods_id',$goods['id'])->first()){
            $collection->delete();
        }else{
            auth()->user()->collect()->create(['goods_id'=>$goods['id']]);
        }
        return back();
    }

    public function mycollect(){
        $orders=Order::where('user_id',auth()->id())->get();
        $collections=Collections::where('user_id',auth()->id())->get();
        return view('home.user.collection',compact('collections','orders'));
    }
}
